Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Data

Public MustInherit Class SportsProvider
    Inherits DataAccess
    Private Shared _instance As SportsProvider = Nothing

    Public Shared ReadOnly Property Instance() As SportsProvider
        Get
            If IsNothing(_instance) Then
                _instance = CType(Activator.CreateInstance( _
                    Type.GetType(Globals.Settings.Sports.ProviderType)), _
                    SportsProvider)
            End If

            Return _instance
        End Get
    End Property
    Public MustOverride Function GetSports() As Generic.List(Of SportDetails)
    Public MustOverride Function CreateSport(ByVal Sport As SportDetails) As Integer
    Public MustOverride Function DeleteSport(ByVal SportID As Integer) As Boolean
    Public MustOverride Function UpdateSport(ByVal Sport As SportDetails) As Boolean
    Public MustOverride Function GetSport(ByVal SportID As Integer) As SportDetails
    Protected Overridable Function GetSportFromReader(ByVal reader As IDataReader) As SportDetails
        'loads up a Sportdetail from a reader
        Dim NewSport As New SportDetails
        With NewSport
            If IsDBNull(reader("GID")) Then .ID = 0 Else .ID = CInt(reader("sportID"))
            If IsDBNull(reader("sportName")) Then .sportName = "" Else .sportName = reader("sportName").ToString
        End With
        Return NewSport
    End Function

    Protected Overridable Function GetSportCollectionFromReader( _
            ByVal reader As IDataReader) _
            As List(Of SportDetails)
        Dim Sport As New List(Of SportDetails)
        Try
            While (reader.Read)
                Sport.Add(GetSportFromReader(reader))
            End While
        Catch ex As Exception
            Throw New Exception("from get", ex)
        End Try
        Return Sport
    End Function

End Class